package com.tavio.tbs.sprite;

import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.texture.region.TiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.tavio.tbs.scene.SceneManager;
import com.tavio.tbs.structure.Position;
import com.tavio.tbs.unit.Unit;
import com.tavio.tbs.world.WorldMap;

public class UnitSprite extends Sprite{

	private Unit unit;
	
	public UnitSprite(float pX, float pY, float pWidth, float pHeight,
			TiledTextureRegion pTextureRegion,
			VertexBufferObjectManager pSpriteVertexBufferObject) {
		super(pX, pY, pWidth, pHeight, pTextureRegion, pSpriteVertexBufferObject);
		
	}
	
	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
		if(pSceneTouchEvent.isActionUp())
		{
			this.unit.generatePossibleMovements();
			SceneManager.getInstance().removeSelectionRects();
			for(Position position : this.unit.getPossibleMovements())
				SceneManager.getInstance().drawSelectionRectangleOverTile(position, (float)0.85, (float)0.85, this.unit);
		}
		return true;
	}

	public Unit getUnit() {
		return unit;
	}

	public void setUnit(Unit unit) {
		this.unit = unit;
	}
	
}
